import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class LeetCode0739 {


    /**
     * 请根据每日 气温 列表 temperatures}，请计算在每一天需要等几天才会有更高的温度。如果气温在这之后都不会升高，请在该位置用}0 来代替。
     *
     * 示例 1:
     *
     * 输入: temperatures = [73,74,75,71,69,72,76,73]
     * 输出:}[1,1,4,2,1,1,0,0]
     * 示例 2:
     *
     * 输入: temperatures = [30,40,50,60]
     * 输出:}[1,1,1,0]
     * 示例 3:
     *
     * 输入: temperatures = [30,60,90]
     * 输出: [1,1,0]
     * }
     *
     * 提示：
     *
     * 1 <=}temperatures.length <= 105
     * 30 <=}temperatures[i]}<= 100
     */


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String temperatureString = scanner.nextLine();
            temperatureString = temperatureString.replace("temperatures = [", "");
            temperatureString = temperatureString.replace("]", "");

            String[] split = temperatureString.split(",");

            int[] temperatureArray = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                temperatureArray[i] = Integer.valueOf(split[i]);
            }


//            System.out.println(Arrays.toString(getHigherTemperatures(temperatureArray)));
//            System.out.println(Arrays.toString(dailyTemperatures(temperatureArray)));
//            System.out.println(Arrays.toString(thirdDailyTemperature(temperatureArray)));
//            System.out.println(Arrays.toString(forthDailyTemperature(temperatureArray)));
            System.out.println(Arrays.toString(fifthDailyTemperature(temperatureArray)));
        }

    }

    private static int[] getHigherTemperatures(int[] temperatureArray) {
        int[] result = new int[temperatureArray.length];


        for (int i = 0; i < temperatureArray.length; i++) {
            for (int j = i+1; j < temperatureArray.length; j++) {
                if (temperatureArray[j] > temperatureArray[i]) {
                    result[i] = j-i;
                    break;
                }
            }
        }

        return result;
    }


    /**
     * stack<int> st;
     * //此处一般需要给数组最后添加结束标志符，具体下面例题会有详细讲解
     * for (遍历这个数组)
     * {
     * 	if (栈空 || 栈顶元素大于等于当前比较元素)
     *        {
     * 		入栈;
     *    }
     * 	else
     *    {
     * 		while (栈不为空 && 栈顶元素小于当前元素)
     *        {
     * 			栈顶元素出栈;
     * 			更新结果;
     *        }
     * 		当前数据入栈;
     *    }
     * }
     *
     * @param temperatures
     * @return
     */
    public static int[] dailyTemperatures(int[] temperatures)
    {
        Stack<Integer> stack = new Stack<>();

        int size = temperatures.length;
        int[] result = new int[size];
        Arrays.fill(result,0);

        for (int i = 0; i < size; i++)
        {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i])
            {
                int t = stack.pop();
                result[t] = i - t;
            }
            stack.push(i);
        }

        return result;
    }


    public static int[] thirdDailyTemperature(int[] temperatureArray){

        Stack<Integer> stack = new Stack<>();

        int[] result = new int[temperatureArray.length];

        for (int i = 0; i < temperatureArray.length; i++) {
            while (stack.isEmpty() || temperatureArray[i] > stack.peek()) {
                stack.push(i);
            }
            Integer pop = stack.pop();
            result[i] = pop -i;
        }
        return result;

    }


    public static int[] forthDailyTemperature(int[] temperatureArray){

        Stack<Integer> stack = new Stack<>();

        int[] result = new int[temperatureArray.length];

        for (int i = 0; i < temperatureArray.length; i++) {
            while (!stack.isEmpty() && temperatureArray[i] > temperatureArray[stack.peek()]) {
                Integer pop = stack.pop();
                result[pop] = i - pop;
            }
            stack.push(i);
        }
        return result;

    }


    public static int[] fifthDailyTemperature(int[] temperatureArray){

        Stack<Integer> stack = new Stack<>();

        int[] result = new int[temperatureArray.length];

        for (int i = 0; i < temperatureArray.length; i++) {


            if (stack.isEmpty() || temperatureArray[i] < temperatureArray[stack.peek()]) {
                stack.push(i);
            }else {
                while (!stack.isEmpty() && temperatureArray[i] > temperatureArray[stack.peek()]) {
                    Integer pop = stack.pop();
                    result[pop] = i - pop;
                }
                stack.push(i);
            }
        }
        return result;

    }



}
